﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;

using NewPanda.Configure;
using NewPanda.ViewModel;
using P2PLib.Client;

namespace NewPanda
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        #region Field
        private static MusicViewModel musicViewModel;
        private static FileShareViewModel fileShareViewModel;
        private static Client client;

        public static string dir = Environment.CurrentDirectory.ToString();

        #endregion

        protected override void OnStartup(StartupEventArgs e)
        {
            //创建文件夹;
            AppUtils.CreateFolders();
            musicViewModel = AppUtils.LoadMusicViewModel();
            fileShareViewModel = AppUtils.LoadFileShareViewModel();


            //create the client instance
            client = new Client(RedPandaConfig.serverIp, RedPandaConfig.serverPort,AppUtils.GetClientInfo());
           
            //connect to server
            client.ConnectToServer();
            client.Tasks = fileShareViewModel.TaskList;
            client.Files = fileShareViewModel.FileList;


            base.OnStartup(e);
        }


        public static MusicViewModel MVM
        {
            get
            {
                return musicViewModel;
            }
            set
            {
                musicViewModel = value;
            }
        }

        public static FileShareViewModel FSVM
        {
            get
            {
                return fileShareViewModel;
            }
            set
            {
                fileShareViewModel = value;
            }

        }

        public static Client Client
        {
            get
            {
                return client;
            }
        }
    }
}
